define([
  'jquery',
  'underscore',
  'backbone',
  'models/user/UserModel',
  'text!templates/order/orderTemplate.html'
], function($, _, Backbone,UserModel, orderTemplate){
   var getKV=function(id){       // ham lay danh sach cac mon dua vao table theo tham so id
        var data = []; //tao mang rong
        var viewModel = { 
            vendors: ko.observableArray(data),  // gan mang data vao vendors
        };
        ko.applyBindings(viewModel, $(".table")[0]); // applyBindings vao element co class="table" o phan tu thu 0. 

       var khuvuc = function() {
            var self = this;
            self.category_khuvuc = ko.observable();
            self.category_nhom = ko.observable();
            self.category_mon= ko.observable();
            self.ban = ko.observable();
            self.nhom = ko.observable();
            self.mon = ko.observable();
            self.sl = ko.observable('11');

           

            // Whenever the category changes, reset the product selection
            self.category_khuvuc.subscribe(function() {
                self.ban(undefined);
            });
            self.category_nhom.subscribe(function() {
                self.mon(undefined);
            });
            self.category_mon.subscribe(function() {
                self.sl('10');
            });
        };
         ko.applyBindings(new khuvuc(), $(".form")[0]);   //applyBindings vao form 

        

       $.ajax({ // bat dau xu li bang ajax
            url: "server.php",        //url server xu ly du lieu
            type: "POST",             // phuong thuc post
            data: {getKhuvucAndBan:id},   // gan du lieu vao bien data de truyen di theo id o tren truyen vao
            success: function (data) {
               getData = $.parseJSON(data); // lay du lieu tra ve va chuyen ve kieu ban dau
               for (var i = 0; i < getData.length; i++) {
                  //console.log(getData[i].ban.soban+"--"+ getData[i].makv+"--"+getData[i].tenkv);           
               };
              viewModel.vendors(getData); // gan di lieu moi vao bien getData va apply vao viewModel
             // viewModel.allItems(getData);
            }
        });     
      };// ket thuc ham getKV()

  var OrderView = Backbone.View.extend({
    el: $("#contentPage"),

    render: function(){
      console.log("-->OrderView.js");
      $('.menu li').removeClass('active');
      $('.menu li a[href="#/add"]').parent().addClass('active');
      this.$el.html(orderTemplate);
      var getkv= new getKV("all");  // goi ham lay danh sach khu vuc va truyen tham so vao
    },
	events: {
		
	},


  });
  
  return OrderView;
  
});